<?php
ob_start();
session_start();
//print_r($_SESSION);
require_once "includes/config.php";
require_once "includes/functions.php";

if(isset($_POST['hidNewAd']) && $_POST['hidNewAd']=="hidNewAd")
{
    
	mysql_query("INSERT INTO tbl_advertise SET ad_id='',
	                                           full_name='".addslashes($_POST['full_name'])."',
											   company_name='".addslashes($_POST['comp_name'])."',
											   email_address='".addslashes($_POST['email'])."',
											   phone='".addslashes($_POST['phone'])."',
											   web_url='".addslashes($_POST['web'])."',
											   description='".addslashes($_POST['ad_desc'])."',
											   post_date='".date('Y-m-d')."'");
	header("location: advertise.php?msg=true");
}

/*if(empty($_GET['sid'])) {
	header("Location:index.php?notFound");
}

$sid = $_GET['sid'];

$sqlChkStore = "SELECT * FROM tbl_seller_store WHERE seller_id='$sid'";
$rstChkStore = mysql_query($sqlChkStore) or die(mysql_error());
//echo mysql_num_rows($rstChkStore);
if(mysql_num_rows($rstChkStore)==0) {
	header("Location:index.php?store=$sid");
}

//check user session
$user = checkSession();
//print_r($user);
$userId= $user['id'];
$userName= $user['name'];
$userType= $user['type'];



$rsjobcnt=mysql_query("select count(*) as cnt from tbl_post where category_id=2 AND  posted_by=".$_GET['sid']."") or die(mysql_error());
$rowjcnt=mysql_fetch_array($rsjobcnt);
$jobcnt=$rowjcnt['cnt'];

$rsjobcnt=mysql_query("select count(*) as cnt from tbl_post where category_id=2 AND  posted_by=".$_GET['sid']."") or die(mysql_error());
$rowjcnt=mysql_fetch_array($rsjobcnt);
$jobcnt=$rowjcnt['cnt'];

$jobcnt=0;
$clscnt=0;

$rsjobcnt=mysql_query("select count(*) as cnt from tbl_post where category_id=2 AND  posted_by=".$_GET['sid']."") or die(mysql_error());
$rowjcnt=mysql_fetch_array($rsjobcnt);
$jobcnt=$rowjcnt['cnt'];

$rsclscnt=mysql_query("select count(*) as cnt from tbl_post where category_id=5 AND  posted_by=".$_GET['sid']."") or die(mysql_error());
$rowclscnt=mysql_fetch_array($rsclscnt);
$clscnt=$rowclscnt['cnt'];


 if(!empty($_GET['sid'])) { 
	 $sqlSelStore="SELECT * FROM tbl_seller_store WHERE seller_id=".$_GET['sid'];
	 //echo $sqlSelStore;
	 $rstSelStore=mysql_query($sqlSelStore) or die(mysql_error());
	 $rowSelStore=mysql_fetch_array($rstSelStore);
	 $storeId = $rowSelStore['seller_store_id'];
	 $sellerName=$rowSelStore['seller_name'];
	 $storeName=$rowSelStore['store_name'];
	 $storeDescription=$rowSelStore['store_description'];
	 $storeLogo=$rowSelStore['store_logo'];
	 $storeThumb=$rowSelStore['store_image_thumb'];
	 
	 $storeGuidelines=$rowSelStore['store_guidelines'];
	 $newsletterSettings=$rowSelStore['newsletter_settings'];
	 $store_guidelines=$rowSelStore['store_guidelines'];
	//$offerSettings=0;
	 $offer=$rowSelStore['offer'];
	 
	 
	 
	 $ss = mysql_query("select googleMapKey from tbl_settings where setting_id=1") or die(mysql_error());
	 $tbl_settings = mysql_fetch_array($ss);
	 if($tbl_settings) $googleMapKey = $tbl_settings['googleMapKey'];  else $googleMapKey='';
     
	 $user_id = $_SESSION['user_id_sess'];

	 $qry = mysql_query("select * from tbl_users where user_id=$user_id") or die(mysql_error());
		   $cnt_users=mysql_num_rows($qry);
		   if($cnt_users==1)
		   {
			$users = mysql_fetch_array($qry);
			$address_line_1 	= $users['address_line_1'];
			$address_line_2 	= $users['address_line_2'];
			$address_line_3 	= $users['address_line_3'];
			$city		= $users['city'];
			$state		= $users['state'];
			$country		= $users['country'];
			$zip		= $users['zip'];
			
			
			$business_name=$users['business_name'];
			$address_line_1=$users['address_line_1'];
				
			
			
			$address_of_user	= $address_line_1;
			if($address_line_2!='')
			 $address_of_user.=",".$address_line_2;
			if($address_line_3!='')
			 $address_of_user.=",".$address_line_2;
			if($city!='')
			 $address_of_user.=",".$city;
			if($state!='')
			 $address_of_user.=",".$state;
			
			$cqry = mysql_query("select country_name from tbl_country where country_id=$country") or die(mysql_error());
			$tbl_country = mysql_fetch_array($cqry);
			if($tbl_country)
			{
			 $address_of_user.=",".$tbl_country['country_name'];
			}
			
			if($zip!='')
			{
			 $address_of_user.=",".$zip;
			}
		     
		     
		   }
}
*/?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Swapen - Advertise with US
</title>
<script src="js/spry/SpryTabbedPanels.js" type="text/javascript"></script>
<link href="js/spry/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/functions.js"></script>

<link href="includes/style.css" rel="stylesheet" type="text/css" />

</head>

<body>

<table width="950" border="0" align="center" bgcolor="#FFFFFF">
  <tr>
    <td height="119"><?php include_once "header1.php";?></td>
  </tr>
  <tr>
    <td height="193" class="container">
	<form name="frmNewAd" id="frmNewAd" method="post" action="" enctype="multipart/form-data" onsubmit="return ad_validation();">    
	<input type="hidden" name="hidNewAd" id="hidNewAd" value="hidNewAd">
<table width="100%" border="0">
  <tr>
    <td class="contentHeader" colspan="3"><h2>Advertise with US</h2></td>
  </tr>
  <tr>
    <td colspan="3">
	<?php
	if(isset($_GET['msg']) && $_GET['msg']=="true") { 
		echo "<div id='suc-msg' align='center'> Your request has been successfully post to administrator.</div>"; 
	} 
	?></td>
	<tr>
		<td width="34%" align="right">Full Name</td>
		<td width="2%" align="center"><strong>:</strong></td>
		<td width="64%" align="left"><input type="text" name="full_name" id="full_name" style="width:450px;"></td>
    </tr>
	<tr>
		<td align="right">Company Name</td>
		<td align="center"><strong>:</strong></td>
		<td align="left"><input type="text" name="comp_name" id="comp_name" style="width:450px;"></td>
    </tr>
	<tr>
		<td align="right">Email Address</td>
		<td align="center"><strong>:</strong></td>
		<td align="left"><input type="text" name="email" id="email" style="width:450px;"></td>
    </tr>
	<tr>
		<td align="right">Phone # to reach on</td>
		<td align="center"><strong>:</strong></td>
		<td align="left"><input type="text" name="phone" id="phone" style="width:450px;"></td>
    </tr>
	<tr>
		<td align="right" valign="top">Website Url</td>
		<td align="center" valign="top"><strong>:</strong></td>
		<td align="left">http://<input type="text" name="web" id="web" style="width:450px;"><br />
		<font color="#FF0000">example- www.google.com</font></td>
    </tr>
	<tr>
		<td align="right" valign="top">Description of the type of advertisement you are interested in and if it a website?</td>
		<td align="center" valign="top"><strong>:</strong></td>
		<td align="left"><textarea name="ad_desc" id="ad_desc" style="height:100px; width:450px; font-size:12px;"></textarea></td>
    </tr>
	<tr>
		<td colspan="2">&nbsp;</td>
		<td align="left"><input type="submit" id="submitbutton" name="submitbutton" value="Submit"></td>
    </tr>
</table></form>
</td>
  </tr>
  <tr>
    <td height="80"><?php include_once "footer.php";?></td>
  </tr>
</table></body>

<script language="javascript">
function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ad_validation()
{
		 if (document.frmNewAd.full_name.value.search(/\S/)== -1)
		 {
		   alert("Please Enter Full Name")
		   document.frmNewAd.full_name.focus();
		   return false;
		 }
		 
		 if (document.frmNewAd.comp_name.value.search(/\S/)== -1)
		 {
		   alert("Please Enter Company Name")
		   document.frmNewAd.comp_name.focus();
		   return false;
		 }
		 
		var emailID=document.frmNewAd.email
		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please Enter your Email ID")
			emailID.focus()
			return false
		}
		if (echeck(emailID.value)==false){
			emailID.value=""
			emailID.focus()
			return false
		}

		 if (document.frmNewAd.phone.value.search(/\S/)== -1)
		 {
		   alert("Please Enter Phone Number")
		   document.frmNewAd.phone.focus();
		   return false;
		 }

		 if (document.frmNewAd.web.value.search(/\S/)== -1)
		 {
		   alert("Please Enter Website Url")
		   document.frmNewAd.web.focus();
		   return false;
		 }
		 
		 if (document.frmNewAd.ad_desc.value.search(/\S/)== -1)
		 {
		   alert("Please Enter Description")
		   document.frmNewAd.ad_desc.focus();
		   return false;
		 }
	return true;
}
</script>

